package com.jy.wms.service;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.jy.wms.common.annotions.BaseServiceDescribe;
import com.jy.wms.common.base.BaseService;
import com.jy.wms.common.base.DictionaryInfo;
import com.jy.wms.common.base.ServiceException;
import com.jy.wms.common.base.SucessException;
import com.jy.wms.dao.WmsOwnerOrdertypeMapper;
import com.jy.wms.pojo.WmsOwnerOrdertype;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
* @ClassName: WmsOwnerOrdertypeService.java
* @Description: TODO(这里用一句话描述这个类的作用)
* @Author Jane
* @Date Tue Aug 29 15:42:49 CST 2017
*/

@Service
public class WmsOwnerOrdertypeService extends BaseService<WmsOwnerOrdertypeMapper,WmsOwnerOrdertype> {

    @Autowired
    private SysDictionaryService sysDictionaryService;

 /**
 * 插入一条记录
 * @param entity 实体对象
 * @return int
 */
 @BaseServiceDescribe(moduleName = "货主订单类型管理",btnName = "新增货主订单类型")
public void baseInsert( WmsOwnerOrdertype entity)throws ServiceException,SucessException {
     int flag=dao.baseInsert(entity);
     if(flag<1){
         throw  new ServiceException("新增货主订单类型失败");
     }

}

/**
* 插入一条记录（匹配有值的字段）
* @param entity 实体对象
* @param database 数据库名称
* @return int
*/
public Integer baseInsertSelective( WmsOwnerOrdertype entity,String database ){
     return dao.baseInsertSelective(entity);
}

/**
* 删除（根据主键ID删除）
* @param id 主键
* @param database 数据库名称
* @return int
*/
public Integer baseDeleteByPrimaryKey( String id,String database ){
     return dao.baseDeleteByPrimaryKey(id);
}

/**
* 删除（根据ID 批量删除）
* @param idList 主键ID列表
* @param database 数据库名称
* @return int
*/
public Integer baseDeleteBathPrimaryKeys( List<String> idList,String database ){
     return dao.baseDeleteBathPrimaryKeys(idList);
}

/**
* 分页查询
* @param entity 实体
* @return Page<WmsOwnerOrdertype>
*/
@BaseServiceDescribe(moduleName = "货主订单类型管理",btnName = "分页查询货主订单类型")
public Page<WmsOwnerOrdertype> baseSelectPage(WmsOwnerOrdertype entity)throws ServiceException{
    Page<WmsOwnerOrdertype> list=null;
    try {
        PageHelper.startPage(entity.getPage(), entity.getRows());
       list = (Page<WmsOwnerOrdertype>) dao.baseSelectPage(entity);
        for (WmsOwnerOrdertype wmsOwnerOrdertype : list) {
            //获取否采集SN码值
            String value = "";
            value = sysDictionaryService.getTypeName(DictionaryInfo.wms_owner_ordertype_cjsn.toString(), wmsOwnerOrdertype.getCjsn());
            if(value == null||value==""){
                throw  new ServiceException();
            }
            wmsOwnerOrdertype.setShow_cjsn(value);
            //获取分类的值
            value = sysDictionaryService.getTypeName(DictionaryInfo.wms_owner_ordertype_fl.toString(), wmsOwnerOrdertype.getFl());
            if(value == null||value==""){
                throw  new ServiceException();
            }
            wmsOwnerOrdertype.setShow_fl(value);
        }
        return list;
    }catch (Exception e) {
        throw  new ServiceException("查询货主订单类型失败",e);
    }

}

/**
* 查询（根据主键ID查询）
* @param id 主键ID
* @return WmsOwnerOrdertype
*/
public WmsOwnerOrdertype baseSelectByPrimaryKey( String id){
    WmsOwnerOrdertype entity= dao.baseSelectByPrimaryKey(id);
    //获取否采集SN码值
    String value ="";
    System.err.println(DictionaryInfo.wms_owner_ordertype_cjsn.toString());
    value = sysDictionaryService.getTypeName(DictionaryInfo.wms_owner_ordertype_cjsn.toString(),entity.getCjsn());
    entity.setShow_cjsn(value);
    //获取分类的值
    value = sysDictionaryService.getTypeName(DictionaryInfo.wms_owner_ordertype_fl.toString(),entity.getFl());
    entity.setShow_fl(value);
     return entity;
}

/**
* 查询（根据ID 批量查询）
* @param idList 主键ID列表
* @param database 数据库名称
* @return list
*/
public Integer baseSelectBathPrimaryKeys( List<WmsOwnerOrdertype> idList,String database ){
     return dao.baseSelectBathPrimaryKeys(idList);
}

/**
*修改 （匹配有值的字段）
* @param entity 主键ID列表
* @return int
*/
@BaseServiceDescribe(moduleName = "货主订单类型管理",btnName = "修改货主订单类型")
public void baseUpdateByPrimaryKeySelective( WmsOwnerOrdertype entity)throws ServiceException,SucessException{
   int flag=dao.baseUpdateByPrimaryKeySelective(entity);
   if(flag<1){
       throw  new ServiceException("修改货主订单类型失败");
   }
}


/**
*修改（根据主键ID修改）
* @param entity 主键ID列表
* @return int
*/
public Integer baseUpdateByPrimaryKey( WmsOwnerOrdertype entity){
     return dao.baseUpdateByPrimaryKey(entity);
}

    /**
     * 修改（根据ID 批量修改）
     * @param idList 主键ID列表
     * @return int
     */
    public Integer baseUpdateByPrimaryKeys( List<String> idList,String hzId){
        return dao.baseUpdateByPrimaryKeys(idList,hzId);
    }

    /**
     * 修 改 所有的改货主ID下所有库位归零
     * @param sshzid 所属货主ID
     * @return int
     */
    public Integer baseUpdateALLZero( String sshzid){
        return dao.baseUpdateALLZero(sshzid);
    }
    /**
     *订单类型名称去重
     * @param ddlx 订单类型
     * @param sshzid 货主ID
     * @param ckid 仓库ID
     * @return String
     */
    @BaseServiceDescribe(moduleName = "货主订单类型管理",btnName = "订单类型名称去重")
    public Integer duplicateByDdlx( String ddlx,String id,String sshzid,String ckid)throws ServiceException{
    try{
        return  dao.duplicateByDdlx(ddlx,id,sshzid,ckid);
    }catch(Exception e){
        throw new ServiceException("货主订单类型去重",e);
    }
    }
}
